﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Scheduler
{
    /**Class: ScheduleDateSelector
     * @author Sara Tuohy
     * @version 1.0
     * Course : ITEC 4860 Spring, 2012
     * Written: April, 2012
     * This form allows the users to select the date for which 
     * they would like a schedule generated.
     */
    public partial class ScheduleDateSelector : Form
    {
        /**
         * lets us know if a valid date has been selected                */
        private bool goodDateSelected;

        /**
         * Default constructor calls setup() to 
         * configure controls
         */
        public ScheduleDateSelector()
        {
            InitializeComponent();
            setup();
        }

        /**Method: setup
         * Initialize variables for form
         */
        private void setup()
        {
            goodDateSelected = false;
            instructionLabel.Text = "Please select the date for which" + "\n" + "the schedule will be generated: ";
            scheduleDateTimePicker.Text = DateTime.Today.AddDays(7).ToString();     //set default to next week
            submitButton.DialogResult = DialogResult.OK;
            cancelButton.DialogResult = DialogResult.Cancel;
        }

        /**Method: dateWasSelected
         * Lets the calling panel know if a valid date was selected
         * @return true if valid date
         */
        public bool dateWasSelected()
        {
            return goodDateSelected;
        }

        /**Method: SubmitButton_Click
         * Validates the date and updates the goodDateSelected bool
         * More importantly, returns DialogResult.OK
         */
        private void SubmitButton_Click(object sender, EventArgs e)
        {

            if (Convert.ToDateTime(scheduleDateTimePicker.Text) < System.DateTime.Today)
            {
                MessageBox.Show("Date for schedule must be today or later.");
            }
            else
            {
                goodDateSelected = true;
            }
        }

        /**Method: CancelButton_Click
         * Validates the date and updates the goodDateSelected bool
         * More importantly, returns DialogResult.Cancel
         */
        private void cancelButton_Click(object sender, EventArgs e)
        {
            //no action needed - automatically returns DialogResult.Cancel ...
        }
    }
}
